home *** CD-ROM | disk | FTP | other *** search
- head 1.3;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.3
- date 89.06.07.22.14.25; author jhh; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 89.04.10.11.12.16; author jhh; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 89.03.06.12.58.35; author jhh; state Exp;
- branches ;
- next ;
-
-
- desc
- @
- @
-
-
- 1.3
- log
- @Spring cleaning - new mount table format, bug fixes
- @
- text
- @/*
- * exec.c --
- *
- * Routines that provide a nice interface for execing routines with a
- * variable number of parameters.
- *
- * Copyright 1989 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/admin/fsattach/RCS/exec.c,v 1.2 89/04/10 11:12:16 jhh Exp $ SPRITE (Berkeley)";
- #endif /* not lint */
-
- #include "fsattach.h"
- #include <varargs.h>
-
-
- static char *argArray[MAX_EXEC_ARGS];
- static int argCount;
- static char *routineName;
- /*
- *----------------------------------------------------------------------
- *
- * StartExec --
- *
- * Initialize data structures for doing an exec. The routine name must
- * point to an area of storage that is not modified until DoExec()
- * is called.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Arg count is set to 1, routine name stored and first arg stored.
- *
- *----------------------------------------------------------------------
- */
-
- void
- StartExec(routine, firstArg)
- char *routine;
- char *firstArg;
- {
- routineName = routine;
- argArray[0] = firstArg;
- argCount = 1;
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * AddExecArgs --
- *
- * The list of arguments is added to the array to be passed to exec.
- * The storage used by the arguments must not be modified until
- * DoExec is called.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The argument array and arg count are modified.
- *
- *----------------------------------------------------------------------
- */
- #ifdef lint
- /*VARARGS*/
- /*ARGSUSED*/
- void
- AddExecArgs(foo)
- char *foo;
- {}
-
- #else
-
- void
- AddExecArgs(va_alist)
- va_dcl
-
- {
- char *string;
-
- va_list args;
-
- va_start(args);
- for(string = va_arg(args, char *);
- string != NULL;
- string = va_arg(args, char *), argCount++) {
-
- if (argCount >= MAX_EXEC_ARGS) {
- (void) fprintf(stderr, "Too many args to exec.\n");
- return;
- }
- argArray[argCount] = string;
- }
- }
- #endif
-
- /*
- *----------------------------------------------------------------------
- *
- * DoExec --
- *
- * Calls Exec with the arguments built up so far.
- *
- * Results:
- * Process id of child process, -1 if there was an error.
- *
- * Side effects:
- * Child process is forked.
- *
- *----------------------------------------------------------------------
- */
-
- int
- DoExec()
- {
- int pid;
- int i;
-
- if (argCount >= MAX_EXEC_ARGS) {
- (void) fprintf(stderr, "Too many args to exec.\n");
- return -1;
- }
- argArray[argCount] = NULL;
- if (verbose) {
- for (i = 0; i < argCount; i++) {
- printf("%s ", argArray[i]);
- }
- putchar('\n');
- }
- if (printOnly) {
- return 0;
- }
- pid = fork();
- if (pid == 0) {
- (void) execvp(routineName, argArray);
- (void) fprintf(stderr, "Exec failed.\n");
- (void) perror("");
- (void) _exit(EXEC_FAILED);
- }
- return pid;
- }
-
- @
-
-
- 1.2
- log
- @First working version
- @
- text
- @d18 1
- a18 1
- static char rcsid[] = "$Header: /sprite/users/jhh/fsattach/RCS/exec.c,v 1.1 89/03/06 12:58:35 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
- d125 2
- a126 2
- int pid;
- int i;
- d140 1
- a140 1
- return -1;
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d2 1
- a2 1
- * module.c --
- d4 2
- a5 1
- * Description.
- d18 1
- a18 1
- static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
- d47 1
- a47 1
- StartExec(routine)
- d49 1
- d52 1
- a52 1
- argArray[0] = routine;
- d62 2
- d114 1
- a114 1
- * None.
- d117 1
- a117 1
- * Exec is called.
- d133 1
- a133 2
- if (printOnly) {
- printf("Execing %s with parameters:\n", routineName);
- d138 2
- d142 1
- a142 1
- pid = vfork();
- d144 4
- a147 3
- (void) execv(routineName, argArray);
- (void) fprintf(stderr, "YOW! Exec returned.\n");
- (void) _exit(HARDERROR);
- @
-